require(['./config'], () => {
  require(['cookie','header','footer','jquery','bootstrap'], (cookie) => {
    class Login {
      constructor() {
        this.goLogin()
      }
      goLogin() {
        $('#go').on('click', function() {
          let userName = $('#userName').val()
          let password = $('#password').val()
          let userList = JSON.parse(localStorage.getItem('userList'))
          if (userList) {
            let flag = userList.some(item => {
              return item.name === userName && item.pwd === password
            })
            
            if (flag) {
              $.cookie('user',userName, { expires: 5, path: '/' })
              window.open('../index.html')
            } else {
              alert('账号或者密码错误，请重新输入')
              window.open('loginPage.html')
            }
          } else {
            alert('请先注册一个账号')
            window.open('register.html')
          }
        })
      }
    }
    new Login()
  })
})